package top.suven.base.http.admin.config.mqfail;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.suven.base.http.admin.config.service.MqFailInfoWebService;
import top.suven.base.http.enums.SysMsgEnumType;
import top.suven.base.http.exception.SystemRuntimeException;

import java.util.Arrays;
import java.util.Optional;

/**
 * @ClassName:
 * @Description:
 * @Author lixiangling
 * @Date 2018/9/6 19:55
 * @Copyright: (c) 2018 gc by https://www.gc.com.cn/
 * @Version : 1.0.0
 * --------------------------------------------------------
 * modifyer    modifyTime                 comment
 * <p>
 * --------------------------------------------------------
 */
@Component
public class MqFailExecCore {
    @Autowired
    private MqFailInfoWebService mqFailInfoWebService;

    private MqFailExecService getExecService(String topicName){
        MqFailExecService mqFailExecService = null;
        Optional<String> optional = Arrays.stream(MqFailExecEnum.values()).filter(e->e.getTopicName().equals(topicName)).map(e->e.getTopicName()).findAny();
        if(optional == null || StringUtils.isBlank(optional.get())){
            throw new SystemRuntimeException(SysMsgEnumType.SYS_UNKOWNN_FAIL);//TODO
        }
        try {
        mqFailExecService = (MqFailExecService)Class.forName(optional.get()).newInstance();
        }catch (Exception e){

        }
        return mqFailExecService;
    }
    /**
     * @Title: 补偿MQ消费失败
     * @Description:
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/9/7 10:04
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void compensate(Long[] ids,String topicName){
        MqFailExecService mqFailExec = getExecService(topicName);

    }
    /**
     * @Title: 全部补偿mq消费失败
     * @Description:
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/9/7 10:04
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void compensateBatch(String topicName){
        MqFailExecService mqFailExec = getExecService(topicName);
    }
}
